| Conditions | 3 |
| Paths | 2 |
| Total Lines | 74 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import fse from 'fs-extra' |
||
| 20 | constructor(enforcer) { |
||
| 21 | if(enforcer != singletonEnforcer) throw 'Cannot construct Plugins singleton' |
||
| 22 | this._plugins = [] |
||
| 23 | this.fn = [] |
||
| 24 | var pluginsDir = path.join(config.root, config.plugins.url) |
||
| 25 | if(folderUtils.isFolder(pluginsDir)) { |
||
| 26 | this._plugins = FileParser.getFolders(pluginsDir, true, 0) |
||
| 27 | Array.prototype.forEach.call(this._plugins, (plugin) => { |
||
| 28 | // has hooks |
||
| 29 | var plugHooks = path.join(plugin.path, config.hooks.url) |
||
| 30 | if(folderUtils.isFolder(plugHooks)) { |
||
| 31 | var plugHooksFile = path.join(plugHooks, 'hooks.js') |
||
| 32 | var h = require(plugHooksFile) |
||
| 33 | plugin.hooks = h.default |
||
| 34 | }else { |
||
| 35 | plugin.hooks = null |
||
| 36 | } |
||
| 37 | |||
| 38 | // has partials |
||
| 39 | var plugPartials = path.join(plugin.path, config.pluginsPartials) |
||
| 40 | if(folderUtils.isFolder(plugPartials)) { |
||
| 41 | plugin.partials = plugPartials |
||
| 42 | }else { |
||
| 43 | plugin.partials = null |
||
| 44 | } |
||
| 45 | |||
| 46 | // has templates |
||
| 47 | var plugTemplates = path.join(plugin.path, config.templates.url) |
||
| 48 | if(folderUtils.isFolder(plugTemplates)) { |
||
| 49 | plugin.templates = plugTemplates |
||
| 50 | }else { |
||
| 51 | plugin.templates = null |
||
| 52 | } |
||
| 53 | |||
| 54 | // has process |
||
| 55 | var plugProcess = path.join(plugin.path, 'process') |
||
| 56 | if(folderUtils.isFolder(plugProcess)) { |
||
| 57 | plugin.process = {} |
||
| 58 | var processFiles = FileParser.getFiles(plugProcess, true, 0) |
||
| 59 | Array.prototype.forEach.call(processFiles, (processFile) => { |
||
| 60 | plugin.process[processFile.cleanNameNoExt] = processFile.path |
||
| 61 | }) |
||
| 62 | }else { |
||
| 63 | plugin.process = null |
||
| 64 | } |
||
| 65 | |||
| 66 | // has routes |
||
| 67 | var plugRoutes = path.join(plugin.path, 'routes') |
||
| 68 | if(folderUtils.isFolder(plugRoutes)) { |
||
| 69 | plugin.routes = {} |
||
| 70 | |||
| 71 | var gets = path.join(plugRoutes, 'get') |
||
| 72 | if(folderUtils.isFolder(gets)) { |
||
| 73 | var routesGet = FileParser.getFiles(gets, true, 0) |
||
| 74 | Array.prototype.forEach.call(routesGet, (route) => { |
||
| 75 | route.routePath = `/abe/plugin/${plugin.name}/${route.name.replace('.js', '')}*` |
||
| 76 | }) |
||
| 77 | plugin.routes.get = routesGet |
||
| 78 | } |
||
| 79 | |||
| 80 | var posts = path.join(plugRoutes, 'post') |
||
| 81 | if(folderUtils.isFolder(posts)) { |
||
| 82 | var routesPost = FileParser.getFiles(posts, true, 0) |
||
| 83 | Array.prototype.forEach.call(routesPost, (route) => { |
||
| 84 | route.routePath = `/abe/plugin/${plugin.name}/${route.name.replace('.js', '')}*` |
||
| 85 | }) |
||
| 86 | plugin.routes.post = routesPost |
||
| 87 | } |
||
| 88 | }else { |
||
| 89 | plugin.routes = null |
||
| 90 | } |
||
| 91 | }) |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 161 | export default Plugins |